
// 日期格式化
function timestampFormat(timestamp) {
    function zeroize(num) {
        return (String(num).length == 1 ? '0' : '') + num;
    }
    var curTimestamp = parseInt(new Date().getTime() / 1000); //当前时间戳
    var timestampDiff = curTimestamp - timestamp; // 参数时间戳与当前时间戳相差秒数
    var curDate = new Date(curTimestamp * 1000); // 当前时间日期对象
    var tmDate = new Date(timestamp * 1000); // 参数时间戳转换成的日期对象
    var Y = tmDate.getFullYear(),
        m = tmDate.getMonth() + 1,
        d = tmDate.getDate();
    var H = tmDate.getHours(),
        i = tmDate.getMinutes(),
        s = tmDate.getSeconds();
    if (timestampDiff < 60) { // 一分钟以内
        return "刚刚";
    } else if (timestampDiff < 3600) { // 一小时前之内
        return Math.floor(timestampDiff / 60) + "分钟前";
    } else if (curDate.getFullYear() == Y && curDate.getMonth() + 1 == m && curDate.getDate() == d) {
        return '今天' + zeroize(H) + ':' + zeroize(i);
    } else {
        var newDate = new Date((curTimestamp - 86400) * 1000); // 参数中的时间戳加一天转换成的日期对象
        if (newDate.getFullYear() == Y && newDate.getMonth() + 1 == m && newDate.getDate() == d) {
            return '昨天' + zeroize(H) + ':' + zeroize(i);
        } else if (curDate.getFullYear() == Y) {
            return zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
        } else {
            return Y + '年' + zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
        }
    }
}
// 快速获取当前时间
function getTime() {
    var time = new Date();
    var y = time.getFullYear();
    y = y < 10 ? '0' + y : h
    var h = time.getHours();
    h = h < 10 ? '0' + h : h;
    var m = time.getMinutes();
    m = m < 10 ? '0' + m : m
    var s = time.getSeconds();
    s = s < 10 ? '0' + s : s
    return y + '年' + h + ':' + m + ':' + s;
}

/**
 * 获取随机颜色
 * @returns String
 */
function color() {
    var arr = '0123456789abcdef'.split('')
    var min = 0
    var max = arr.length - 1
    var one = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var two = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var three = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var four = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var five = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var six = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    return '#' + one + two + three + four + five + six
}


/**
 * 判断浏览器内核
 * @returns String
 */
function GetCurrentBrowser() {
    //取得浏览器的userAgent字符串
    var userAgent = navigator.userAgent.toLocaleLowerCase();
    var isChrome = userAgent.indexOf("chrome") > -1; //判断是否谷歌浏览器
    var isOpera = userAgent.indexOf("opera") > -1; //判断是否Opera浏览器
    var isIE = userAgent.match(/msie/) != null || userAgent.match(/trident/) != null;//userAgent.indexOf("compatible") > -1 && userAgent.indexOf("msie") > -1 && !isOpera; //判断是否IE浏览器
    var isFF = userAgent.indexOf("firefox") > -1; //判断是否Firefox浏览器
    var isSafari = userAgent.indexOf("safari") > -1; //判断是否Safari浏览器	
    if (isIE) {
        var IE5 = IE55 = IE6 = IE7 = IE8 = IE9 = IE11 = false;
        var fIEVersion = userAgent.match(/msie ([\d.]+)/) != null ? userAgent.match(/msie ([\d.]+)/)[1] : userAgent.match(/rv:([\d.]+)/)[1];
        IE55 = fIEVersion == 5.5;
        IE6 = fIEVersion == 6.0;
        IE7 = fIEVersion == 7.0;
        IE8 = fIEVersion == 8.0;
        IE9 = fIEVersion == 9.0;
        IE11 = fIEVersion == 11.0;
        if (IE55) {
            return "IE55";
        }
        if (IE6) {
            return "IE6";
        }
        if (IE7) {
            return "IE7";
        }
        if (IE8) {
            return "IE8";
        }
        if (IE9) {
            return "IE9";
        }
        if (IE11) {
            return "IE11";
        }
    }//isIE end
    if (isFF) {
        return "FF";
    }
    if (isOpera) {
        return "Opera";
    }
    if (isChrome) {
        return "Chrome";
    }
}

/**
 * 判断现在是PC还是移动true为PC端，false为手机端
 * @returns Bollean
 */
function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    var flagPc = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flagPc = false;
            break;
        }
    }
    return flagPc;
}
var flagZt = IsPC();


/**
 * 判断是否是微信浏览器
 * @returns Bollean
 */
function isWeiXin() {
    var ua = window.navigator.userAgent.toLowerCase();
    console.log(ua);//mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        return true;
    } else {
        return false;
    }
}
